//
//  THJFabuView.m
//  THJXHW
//
//  Created by 河南德艺 on 17/3/8.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJFabuView.h"
#import "SDAutoLayout.h"
#import "THJTypeItemCell.h"
#import "THJCancelBtnCell.h"

@interface THJFabuView ()<UITableViewDataSource,UITableViewDelegate,THJCancelBtnCellDelegate>
{
    UITableView *_tableview;
}
@end

@implementation THJFabuView

-(instancetype)init{
     
     if (self = [super init]) {
         
         [self creatTableview];
         
     }
     return self;
 }

-(void)creatTableview{
     self.backgroundColor = COLOR(0, 0, 0, 0.6);
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreenHeight-330, ScreenWidth, 330) style:UITableViewStylePlain];
    [_tableview registerNib:[UINib nibWithNibName:@"THJCancelBtnCell" bundle:nil] forCellReuseIdentifier:@"cancel"];
    [_tableview registerNib:[UINib nibWithNibName:@"THJTypeItemCell" bundle:nil] forCellReuseIdentifier:@"type"];
    _tableview.tableFooterView = [[UIView alloc]init];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _tableview.backgroundColor = COLOR(247, 247, 247, 1);
    [self addSubview:_tableview];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 5) {
        return 60;
    }
    return 54;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray * titleArr = @[@"现货",@"团购",@"求购",@"供应",@"招标"];
    NSArray * colorARR = @[COLOR(251, 0, 10, 1),COLOR(235, 56, 20, 1),COLOR(241, 55, 99, 1),COLOR(27, 165, 237, 1),COLOR(21, 158, 34, 1)];
    if (indexPath.row == 5) {
        THJCancelBtnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cancel" forIndexPath:indexPath];
        cell.backgroundColor = COLOR(247, 247, 247, 1);
        cell.delegate = self;
        return cell;
    }else{
        THJTypeItemCell * cell = [tableView dequeueReusableCellWithIdentifier:@"type" forIndexPath:indexPath];
        cell.backgroundColor = COLOR(247, 247, 247, 1);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLabel.text = titleArr[indexPath.row];
        cell.colorLab.backgroundColor = colorARR[indexPath.row];
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(itemClickedOfIndex:)]){
        [self.delegate itemClickedOfIndex:indexPath.row];
    }
}
-(void)cancelBtnClicked{
    if ([self.delegate respondsToSelector:@selector(itemClickedOfIndex:)]){
        [self.delegate itemClickedOfIndex:5];
    }
}
@end
